#ifndef __MCLINEARDIMENSIONVISUAL_H_
#define __MCLINEARDIMENSIONVISUAL_H_

#include <MCGraphicsItem.h>
#include <MCLinearDimension2D.h>

class MCLinearDimensionsVisual : public MCGraphicsItem
{
public:

    MCLinearDimensionsVisual(ICanvas *canvas, MCLinearDimension2D dimension);

    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
    QPainterPath shape() const override;

    void setGripAt(IGripPoint *grip, const MCPoint2D &pos) override;
    void resetGrips() override;

    void update(const MCPoint2D &p1, const MCPoint2D &p2);
    void update(const MCPoint2D &p1, const MCPoint2D &p2, double height);

    MCLinearDimension2D linearDimension() const;

private:

    MCLinearDimension2D transformed() const;

    void drawDimension(QPainter *painter);
    void drawLeaderLines(MCLineSegment2D sourceLine, MCLineSegment2D dimensionLine);
    void drawArrows(MCPoint2D p1, MCPoint2D p2);
    void drawLengthText(QPainter *painter);
    void drawInArrows(MCPoint2D p1, MCPoint2D p2);
    void drawOutArrows(MCPoint2D p1, MCPoint2D p2);

    QPainterPath lineBoundigs(const MCLineSegment2D &line) const;

    void initGripPoints();

private:

    MCLinearDimension2D _dimensionModel;

};

#endif // !__MCLINEARDIMENSIONVISUAL_H_
